<template>
	<div >
		<div>
			<!--<el-select v-model="qcParamsValue" size="mini" filterable style="margin-bottom:10px;" @change="changeParams">
				<el-option v-for="item in selectOptions" :key="item.code" :label="item.name" :value="item.code">
				</el-option>
			</el-select>-->
			<el-table :data="testpanelData.sampleBeans" style="width: 100%" :height = "heightD" size="mini" cell-class-name="batchtablecell" highlight-current-row
				key="1">
				<el-table-column label="序号" width="55px">
					<template slot-scope="scope">
						{{scope.$index+1}}
					</template>
				</el-table-column>
				<el-table-column property="sampleCode" label="样品编号" show-overflow-tooltip>
				</el-table-column>
				<el-table-column property="taskName" label="任务名称" show-overflow-tooltip>
					<template slot-scope="scope">
						{{scope.row.taskName == undefined ? '---':scope.row.taskName}}
					</template>
				</el-table-column>
        <el-table-column property="factDate" label="采样日期" width="115px">
          <template slot-scope="scope">
              {{scope.row.factDate == null || scope.row.factDate == "" || scope.row.factDate == undefined? "---":scope.row.factDate.split(" ")[0]}}
          </template>
        </el-table-column>
				<el-table-column property="sampleName" label="监测点" show-overflow-tooltip>
					<template slot-scope="scope">
						{{scope.row.doBlind ? '***':scope.row.sampleName}}
					</template>
				</el-table-column>
				<el-table-column property="qcTypeName" label="QC类型">
					<template slot-scope="scope">
						{{scope.row.doBlind ? '***':(scope.row.qcTypeName?scope.row.qcTypeName:"---")}}
					</template>
				</el-table-column>
				<template v-for="(col,index) in allItem">
					<el-table-column :label="col.name" :prop="col.item" :key="Math.random()">
						<template slot-scope="scope">
							<span v-if="scope.row[col.item] != undefined">{{scope.row[col.item].value}}</span>
						</template>
					</el-table-column>
				</template>
			</el-table>
		</div>


	</div>
</template>

<script>
	import $ from 'jquery'
	import { mapState } from 'vuex'

	export default {
		data() {
			return {
				viewTitle: [],
				selectOptions:[],//下拉框选项
				qcParamsValue:null,//下拉框绑定值
				allItem:[], //所有的检测项和分析项

			}
		},
		watch: {

		},
		props: ['testpanelData', 'yuanshijiemian'],
		components: {

		},
		mounted() {
			if (!this.yuanshijiemian) { //如果yuanshijiemian为false,即切换视图
				var arr = [];
				for (var i in this.testpanelData.sampleBeans) {


				}
				// this.getSelect(); //获取下拉框值
				this.changeParams('RES002'); //RES002 报出结果
				this.getAllItem(); //获取改能力参数下 所有的检测项和分析项
			}
		},
		computed: {
			...mapState(['tableHeightA']),
			heightD(){
				return (window.innerHeight - 380);
			}
		},
		methods: {
			// 获取质控参数
			//  getSelect() {
			// 	var data = {
			// 		name:this.qcParamsValue
			// 	};
            //     this.$http({
            //         method: 'post',
            //         apiUrl: '/detection/readAllQcNorms.htm',
			// 		params:data,
			// 		isJson:false,
            //     }).then(res => {
            //         if (res.code == 0) {
			// 			this.selectOptions = res.data;
			// 			this.qcParamsValue = this.selectOptions[0].code;

            //         }
            //     })
            // },
			getAllItem() {
				var data = {
					// detectability:this.testpanelData.detectability,
					// method:this.testpanelData.method,
					batch:this.testpanelData.id
				};
                this.$http({
                    method: 'post',
                    apiUrl: '/detection/getAllItemByDete.htm',
					params:data,
					isJson:false,
                }).then(res => {
                    if (res.code == 0) {
						this.allItem = res.data;
                    }
                })
            },
			changeParams(val){
				var tempArr = [];
				for (var i in this.testpanelData.sampleBeans) {
					// 把选中的值的id和改样品分析项和检测项的resultMap对比，
					//如果选中的值和resultMap的属性匹配，
					//把resultMap的属性值赋给样品的新属性（即分析项或者检测项的id）
					for (var j in this.testpanelData.sampleBeans[i].analysisBeans) {
						// tempArr.push(this.testpanelData.sampleBeans[i].analysisBeans[j])
						for(var k in this.testpanelData.sampleBeans[i].analysisBeans[j].resultMap){
							if(val == k){
								this.testpanelData.sampleBeans[i][this.testpanelData.sampleBeans[i].analysisBeans[j].analysis] = this.testpanelData.sampleBeans[i].analysisBeans[j].resultMap[k]

							}
						}

					}
					for (var j in this.testpanelData.sampleBeans[i].itemBeans) {
						for(var k in this.testpanelData.sampleBeans[i].itemBeans[j].resultMap){
							if(val == k){
								this.testpanelData.sampleBeans[i][this.testpanelData.sampleBeans[i].itemBeans[j].item] = this.testpanelData.sampleBeans[i].itemBeans[j].resultMap[k]

							}
						}
						// tempArr.push(this.testpanelData.sampleBeans[i].itemBeans[j])
					}

				}

			},

		}
	}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
